package com.dlg.user.rpc.provider.user;

import com.alibaba.dubbo.config.annotation.Service;
import com.dlg.user.dao.mysql.mappers.user.OjUserRelationShipMapper;
import com.dlg.user.domain.user.OjUserRelationShip;
import com.dlg.user.rpc.api.user.IUserRelationshipRpcService;
import com.dlg.user.rpc.api.vo.user.UserRelationshipRpcVo;
import com.dlg.commons.exception.DataSaveException;
import com.dlg.commons.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigInteger;

/**
 * 用户关系 相关rpc服务
 *
 * @author lhh@gongren.com
 * @since 2017年3月30日 上午9:32:37
 */
@Service(interfaceName="com.dlg.user.rpc.api.user.IUserRelationshipRpcService")
public class UserRelationshipRpcServiceImpl implements IUserRelationshipRpcService {

    private static final long serialVersionUID = 1L;

    @Autowired
    private OjUserRelationShipMapper userRelationShipMapper;

    /**
     * 保存用户关系
     *
     * @param userRelationshipRpcVo
     * @return
     * @author xpp
     * @date 2017年5月3日 下午3:55:46
     */
    @Transactional
    @Override
    public BigInteger addUserRelationship(UserRelationshipRpcVo userRelationshipRpcVo) {
        if (null == userRelationshipRpcVo) {
            throw new DataSaveException("要保存的对象为空");
        }
        if (null == userRelationshipRpcVo.getUserId()) {
            throw new DataSaveException("用户Id为空");
        }
        if (null == userRelationshipRpcVo.getParentUserId()) {
            throw new DataSaveException("父用户Id为空");
        }
        BigInteger id = Utils.id();
        OjUserRelationShip ojUserRelationShip = new OjUserRelationShip();
        ojUserRelationShip.setId(id);
        Utils.copyNotNullObject(userRelationshipRpcVo, ojUserRelationShip);
        userRelationShipMapper.save(ojUserRelationShip);
        return id;
    }

}
